
function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatIndex(date) {
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var minute = date.getMinutes()
  return month + "月" + day + "日" + [hour, minute].map(formatNumber).join(':')
}

function formatWeek(date) {
  var day = date.getDay()
  var week = null
  switch (day) {
    case 1:
      week = "周一"
      break
    case 2:
      week = "周二"
      break
    case 3:
      week = "周三"
      break
    case 4:
      week = "周四"
      break
    case 5:
      week = "周五"
      break
    case 6:
      week = "周六"
      break
    default:
      week = "主日"

  }
  return week
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function converDate(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  return [year, month, day].map(formatNumber).join('/')
}

function converTime(date) {

  var hour = date.getHours() + 1
  var minute = date.getMinutes()


  return [hour, minute].map(formatNumber).join(':')
}

function dateStringToInt(str) {
  var res = Date.parse(str) / 1000
  return res
}

module.exports = {
  formatTime: formatTime,
  formatWeek: formatWeek,
  converDate: converDate,
  converTime: converTime,
  dateStringToInt: dateStringToInt,
  formatIndex: formatIndex
}
